package com.rbac.modules.auth.controller;

import com.rbac.common.utils.R;
import com.rbac.modules.auth.dto.LoginDTO;
import com.rbac.modules.auth.dto.LoginVO;
import com.rbac.modules.auth.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "认证管理")
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {
    private final AuthService authService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    public R<LoginVO> login(@RequestBody @Valid LoginDTO loginDTO) {
        return R.ok(authService.login(loginDTO));
    }

    @Operation(summary = "登出")
    @PostMapping("/logout")
    public R<Void> logout() {
        authService.logout();
        return R.ok();
    }

    @Operation(summary = "获取当前登录用户信息")
    @GetMapping("/info")
    public R<LoginVO> info() {
        Long userId = authService.getLoginUserId();
        String username = authService.getLoginUsername();
        LoginVO loginVO = new LoginVO()
                .setUserId(userId)
                .setUsername(username);
        return R.ok(loginVO);
    }
} 